#include "messageeditarea.h"

#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QScrollBar>

MessageEditArea::MessageEditArea(QWidget *parent):QWidget(parent)
{
    //1. 设置一个必要的尺寸
    this->setFixedHeight(200);
    this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);

    //2. 创建垂直方向的布局管理器
    QVBoxLayout* vlayout = new QVBoxLayout();
    vlayout->setSpacing(0);
    vlayout->setContentsMargins(10, 0, 10,10);
    this->setLayout(vlayout);

    //3. 水平方向再搞一个布局管理器
    QHBoxLayout* hlayout = new QHBoxLayout();
    hlayout->setSpacing(0);
    hlayout->setContentsMargins(10, 0, 20,0);
    hlayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
    vlayout->addLayout(hlayout);

    //4. 上方的4个按钮，创建好并添加到水平布局中
    QString btnStype = "QPushButton {background-color:rgb(245, 245, 245); border:none;} QPushButton:pressed {background-color:rgb(255, 255, 255);}";
    sendImageBtn = new QPushButton();
    sendImageBtn->setFixedSize(35, 35);
    sendImageBtn->setIconSize(QSize(25, 25));
    sendImageBtn->setIcon(QIcon(":/resource/image/image.png"));
    sendImageBtn->setStyleSheet(btnStype);
    hlayout->addWidget(sendImageBtn);

    sendFileBtn = new QPushButton();
    sendFileBtn->setFixedSize(35, 35);
    sendFileBtn->setIconSize(QSize(25, 25));
    sendFileBtn->setIcon(QIcon(":/resource/image/file.png"));
    sendFileBtn->setStyleSheet(btnStype);
    hlayout->addWidget(sendFileBtn);

    sendSpeechBtn = new QPushButton();
    sendSpeechBtn->setFixedSize(35, 35);
    sendSpeechBtn->setIconSize(QSize(25, 25));
    sendSpeechBtn->setIcon(QIcon(":/resource/image/speech.png"));
    sendSpeechBtn->setStyleSheet(btnStype);
    hlayout->addWidget(sendSpeechBtn);

    getHistoryBtn = new QPushButton();
    getHistoryBtn->setFixedSize(35, 35);
    getHistoryBtn->setIconSize(QSize(25, 25));
    getHistoryBtn->setIcon(QIcon(":/resource/image/history_message.png"));
    getHistoryBtn->setStyleSheet(btnStype);
    hlayout->addWidget(getHistoryBtn);


    //5.添加多行编辑框
    textEdit = new QPlainTextEdit();
    textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    textEdit->setStyleSheet("QPlainTextEdit {border:none; background-color:transparent; font-size:14px;padding:10px;color:black;}");
    textEdit->verticalScrollBar()->setStyleSheet("QScrollBar:vertical{width:4px;background-color:rgb(255, 255, 255);}");
    vlayout->addWidget(textEdit);

    //6. 添加发送文本消息按钮
    sendTextBtn = new QPushButton();
    sendTextBtn->setFixedSize(120, 40);
    sendTextBtn->setText("发送");
    // sendTextBtn->set
    QString style = "QPushButton {font-size:16px;color:rgb(7, 193, 96); border:none;background-color:rgb(233, 233, 233);border-radius:10px;}";

    style += "QPushButton:hover{background-color:rgb(210, 210, 210);}";
    style += "QPushButton:pressed {background-color:rgb(200, 200, 200);}";
    sendTextBtn->setStyleSheet(style);
    vlayout->addWidget(sendTextBtn, 0, Qt::AlignRight|Qt::AlignVCenter);
}
